package com.visionblue.business.ship.page.dialog

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.graphics.Bitmap
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.visionblue.business.ship.R
import jp.wasabeef.blurry.Blurry
import kotlinx.android.synthetic.main.dialog_slide.*

/**
 * @author: xlh
 * @date: 2020-05-20 11:36 AM
 * @desc:
 */
class BlurrySlideDialog(
    context: Activity,
    contentId: Int
) :
    Dialog(context, R.style.blurry_slide_dialog) {

    init {
        setContentView(R.layout.dialog_slide)
        LayoutInflater.from(context).inflate(contentId, flContent)
        //根据bug750暂时将虚化放大效果去掉
       /* val bitmap = getScreenViewBitmap(context)
        blurryLayout.setImageBitmap(bitmap)
        Blurry.with(context)
            .radius(5)
            .sampling(1)
            .from(bitmap).into(blurryLayout)*/

        blurryLayout.setOnClickListener {
            //dismiss()
        }
    }


    private fun getScreenViewBitmap(context: Activity): Bitmap? {
        val activityView = context.window?.decorView?.findViewById<View>(android.R.id.content)
        activityView?.isDrawingCacheEnabled = true
        activityView?.destroyDrawingCache()
        activityView?.buildDrawingCache()
        return activityView?.drawingCache
    }

    fun showText(id: Int, text: String?) {
        findViewById<TextView>(id).text = text
    }

    fun setColor(id: Int, colorId: Int) {
        findViewById<TextView>(id)
            .setTextColor(ContextCompat.getColor(context, colorId))
    }

}